<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="ajax.js"></script>
</head>

<body>
    <script>
        // var params = {
        //     page: 1,
        //     size: 10,
        //     type: "is_best",
        //     keywords: "手机"
        // }
        // function formatParams(params) {
        //     var arr = [];
        //     for (var attr in params) {
        //         //attr---page||size||type||keywords
        //         // encodeURIComponent()  编码
        //         arr.push(encodeURIComponent(attr) + "=" + encodeURIComponent(params[attr]))
        //     }
        //     arr.push("t=" + new Date().getTime()) //主要解决浏览器缓存，ajax请求数据不变化的原因
        //     console.log(arr);  //[page=1,size=10,type=is_best,keywords=编码之后的手机,t=1234567890000]
        //     return arr.join("&")
        // }
        // console.log(formatParams(params));
        //page=1&size=10&type=is_best&keywords=%E6%89%8B%E6%9C%BA&t=1628303245775

        ajax({
            url: "http://localhost:3000/data",
            type: "get",
            params: {}
        }).then(result => {
            console.log(result);
        })
    </script>
</body>

</html>